#include "MediaStateBase.h"
#include "MediaGenerator.h"
#include "MediaGlobals.h"
#include "Trace.h"

namespace tsc
{
namespace mgw
{

using namespace tsc::common;

/*******************************************************************************
 *
 * Constructor
 *
 ******************************************************************************/
MediaStateBase::MediaStateBase(const char* name) :
    StateBase(name)
{

} // MediaStateBase::MediaStateBase

/*******************************************************************************
 *
 * Destructor
 *
 ******************************************************************************/
MediaStateBase::~MediaStateBase()
{

} // MediaStateBase::~MediaStateBase


//===================================================================
void
MediaStateBase::handleEvent(
    common::Generator*  generator,
    common::EventData*& eventData)
{
    if (!eventData)
    {
        TRACE(1, "EventData to handle is NULL");
        return;
    }

    switch (eventData->sigNo())
    {
    case MEDIA_SETUP_CONNECTION:
    {
        handleEventSetupConnection(
            static_cast<MediaGenerator*>(generator),
            static_cast<MediaEventSetupConnection*>(eventData),
            eventData);
    }
    break;

    case MEDIA_RELEASE_CONNECTION:
    {
        handleEventReleaseConnection(
            static_cast<MediaGenerator*>(generator),
            static_cast<MediaEventReleaseConnection*>(eventData),
            eventData);
    }
    break;

    default:
        TRACE_ERROR(STR("Event:sigNo=0x%x not handled in switch",
                        eventData->sigNo()));
        EventData::deleteEvent(eventData);
    }
}

//===================================================================
void
MediaStateBase::handleEventSetupConnection(
    MediaGenerator* gen,
    MediaEventSetupConnection* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event MediaEventSetupConnection not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
MediaStateBase::handleEventReleaseConnection(
    MediaGenerator* gen,
    MediaEventReleaseConnection* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event MediaEventSetupConnection not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

} // namespace sgw
} // namespace tsc
